# -*- encoding: utf-8 -*-
import random


def play_game_until_red():
    # 定义出红的概率（0.01%）
    red_probability = 0.0001

    # 初始化计数器
    attempts = 0

    while True:
        attempts += 1
        # 生成一个0到1之间的随机数
        random_number = random.random()

        # 判断是否出红
        if random_number < red_probability:
            return attempts


def run_experiments(num_experiments):
    # 记录每次实验的出红次数
    results = []

    for _ in range(num_experiments):
        attempts_needed = play_game_until_red()
        results.append(attempts_needed)

    # 计算平均值
    average_attempts = sum(results) / num_experiments
    return average_attempts, results


# 运行 1000 次实验
num_experiments = 100
average_attempts, results = run_experiments(num_experiments)

# 输出结果
print(f"10000 次实验的平均出红次数: {average_attempts}")
print(f"前 10 次实验的结果: {results[:10]}")